/*!
 * \file dubbo_core.h
 *
 * \brief 共通定义
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 * 共通使用的宏和结构体
 *
 * \version 1.0
 * \author jikw
 * \date 2016/8/1
 *
 */

#ifndef __DUBBO_CORE_H_
#define __DUBBO_CORE_H_

#include "conntrack.h"
#include "module.h"
#include "frreport_comm.h"
#include "frbyte_buffer.h"

#define MAGIC                                "\xda\xbb"
#define MAGIC_LENGTH                         2
#define ID_LENGTH                            8
#define FLAG_REQUEST                         0x80
#define FLAG_TWOWAY                          0x40
#define FLAG_EVENT                           0x20
#define SIP_TIMEOUT                          5*60//单位秒
#define ARRAY_LEN                            128

//未上报的请求
typedef struct __st_dubbo_report_list
{
    struct timeval st_request_time;
    Frlist_header *p_lst_comm;
    Frlist_header *p_lst_req;
} dubbo_report_list;

//object fields
typedef struct __st_dubbo_fields_list
{
    int i_count;
    char *p_fields_name;
    char *p_fields_value;
} dubbo_fields_list;

typedef struct __st_L7session_dubbo_private
{
    L4_transaction st_l4_trans;                       //数据
    Frreport_body_data *p_st_body_data_req;
    Frreport_body_data *p_st_body_data_resp;
    Frbyte_Packet *p_req_packet;                      //存请求bytebuff数据
    Frbyte_Packet *p_resp_packet;                     //存相应bytebuff数据
    Frhash_header *p_report_list_dubbo;               //未上报的请求
    Frlist_header *p_fields_list_dubbo;               //存map的key和序号
    uint64_t u64_req_id;                              //req ID
    uint64_t u64_resp_id;                             //resp ID
    int i_flag_oneway;                                //oneway标志位 为1 req信息不存hash表
    int i_flag_serialize;                             //序列化方式
    int i_flag_status;                                //resp status位 正常为0x14
    int i_len;
}L7session_dubbo_private;

int dubbo_detect(Conntrack *p_st_conn, Apm_packet *p_st_packet);

int dubbo_analysis(Conntrack *p_st_conn
                  , Apm_packet *p_st_packet
                  , Frhash_header *p_st_hash_report);

int dubbo_session_destroy(void *p_private_session);

void dubbo_session_reset(void *p_private_session);

#endif
